#pragma once
#include <iostream>
#include <string>
#include <functional>
#include <memory>
#include <unistd.h>
#include "Epoll.hpp"

namespace ReactorModule 
{
    class Reactor;  //  添加前向声明
}

namespace ConnectModule
{
    using namespace EpollModule;

    const static int gdefaultfd = -1;

    class Connect
    {
    public:
        Connect():_fd(gdefaultfd)
        {}

        virtual void Send() = 0;
        virtual void Recv() = 0;
        virtual void Except() = 0;

        void SetOwner(ReactorModule::Reactor* owner)
        {
            _owner = owner;
        }
        void SetEvents(uint32_t events)
        {
            _events = events;
        }
        void SetFd(int fd)
        {
            _fd = fd;
        }
        int Fd() {return _fd;}
        uint32_t Events(){return _events;}
        ReactorModule::Reactor* Owner(){return _owner;}
        void Close() {close(_fd);}
        virtual ~Connect()
    {}
    protected:
        // 文件描述符
        int _fd;    
        // 关心的事件
        uint32_t _events;
        // 回指Reactor
        ReactorModule::Reactor* _owner;
    };
}